package at.fhj.swd.pse.domain;

import java.util.List;

import javax.ejb.Stateless;
import javax.inject.Inject;

import org.jboss.logging.Logger;

import at.fhj.swd.pse.data.NewsDAO;
import at.fhj.swd.pse.entities.News;

/**
 * @author Stefan Winkler
 **/

@Stateless
public class NewsServiceImpl implements NewsService {

	private static final Logger log = Logger.getLogger(NewsServiceImpl.class);

	@Inject
	private NewsDAO newsDao;

	public NewsServiceImpl() {
	}

	NewsServiceImpl(final NewsDAO dao) {
		this.newsDao = dao;
	}

	@Override
	public List<News> getAllOrderedByCreation() {
		return this.newsDao.getAllOrderedByCreation();
	}

	@Override
	public News insertNews(final News news) {
		log.info("Insert news: " + news.getTitle());
		return this.newsDao.insert(news);
	}

	@Override
	public News updateNews(final News news) {
		log.info("Update news: " + news.getTitle() + " Id: " + news.getId());
		return this.newsDao.update(news);
	}

}
